package com.patrol.controller;

import com.patrol.pojo.TaskPoint;
import com.patrol.pojo.User;
import com.patrol.service.TaskPointService;
import com.patrol.service.UserService;
import com.patrol.utils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;

/**
 * @author zsc
 * @description: 点位管理接口
 */

@Api(tags = "点位管理接口")
@RestController
@RequestMapping("/api/taskpoint")
@CrossOrigin
public class TaskPointController {
    @Resource
    private TaskPointService taskPointService;

    /**
     * 添加点位
     * @param taskPoint
     * @return
     */
    @ApiOperation(value = "添加点位")
    @PostMapping("insertPoint")
    public Result insertPoint(@RequestBody TaskPoint taskPoint){
        boolean flag = taskPointService.save(taskPoint);
        if (flag) {
            return Result.ok();
        }else {
            return Result.fail();
        }
    }

    /**
     * 根据ID查询点位
     * @param taskId
     * @return
     */
    @ApiOperation(value = "根据ID查询点位")
    @GetMapping("selectPointById/{taskId}")
    public Result selectPointById(@PathVariable Integer taskId){
        TaskPoint taskPoint = taskPointService.selectPointById(taskId);
        return Result.ok(taskPoint);
    }

    /**
     * 查询所有点位
     * @return
     */
    @ApiOperation(value = "查询所有点位")
    @GetMapping("selectAll")
    public Result selectAll(){
        List<TaskPoint> list = taskPointService.selectAllPoint();
        return Result.ok(list);
    }

    /**
     * 根据ID逻辑删除点位
     * @param id
     * @return
     */
    @ApiOperation(value = "根据ID逻辑删除点位")
    @DeleteMapping("{id}")
    public Result deleteOneById(@PathVariable Long id){
        boolean flag = taskPointService.removeById(id);
        if (flag){
            return Result.ok();
        }else {
            return Result.fail();
        }
    }

    /**
     * 批量逻辑删除点位
     * @param idList
     * @return
     */
    @ApiOperation(value = "批量逻辑删除点位")
    @DeleteMapping("batchRemove")
    public Result batchRemovePoint(@RequestBody List<Long> idList){
        taskPointService.removeByIds(idList);
        return Result.ok();
    }

    /**
     * 根据ID修改点位信息
     * @param taskPoint
     * @return
     */
    @ApiOperation(value = "根据ID修改点位信息")
    @PostMapping("updatePoint")
    public Result updatePointById(@RequestBody TaskPoint taskPoint){
        boolean flag = taskPointService.updateById(taskPoint);
        if (flag) {
            return Result.ok();
        } else {
            return Result.fail();
        }
    }

    /**
     * 定位打卡
     * @param taskId
     * @return
     */
    @ApiOperation(value = "打卡")
    @PostMapping("clockPoint")
    public Result updateStatueAndNum(@RequestBody TaskPoint taskPoint){
        boolean flag = taskPointService.clockPoint(taskPoint);
        if (flag) {
            return Result.ok();
        } else {
            return Result.fail();
        }
    }
}
